<template>
    <rx-layout>
        <div slot="left" width="200" showButton="true">
            <rx-fit>
                <rx-category-treeeditor
                    cat-key="BPM"
                    :statisticConfig="statisticConfig"
                    read-key="inst.read"
                    :edit="false"
                    @handSelect="selectTreeNode"
                    :async="true"
                    v-if="isShowManageTree"
                    :isAdmin="isManageToTree"
                    :treeRootList="treeRootList"
                    :isBpmClient="isMyBpmClient"
                    :isMyBpm="isMyBpmClient"
                ></rx-category-treeeditor>
            </rx-fit>
        </div>
        <div slot="center">
            <rx-fit  :isheader="isheader">
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <rx-list-title :title="i18n('list.auditTrail','我的发起')"></rx-list-title>
                    <span class="search-btn-box" v-if="!isheader">
                        <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
                    </span>
                </div>
                <div btnalign="right"  slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.itemTitle','事项标题')">
                                    <a-input :placeholder="i18n('form.itemTitle','事项标题','input')" v-model="queryParam['Q_b.SUBJECT__S_LK']" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.bsNum','单号')">
                                    <a-input :placeholder="i18n('form.bsNum','单号','input')" v-model="queryParam['Q_b.BILL_NO__S_LK']" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('list.createTime','创建时间') + i18n('list.from','从')">
                                    <a-date-picker
                                        style="width: 100%"
                                        :placeholder="i18n('list.createTime','请输入创建时间','input')"
                                        v-model="queryParam['Q_b.CREATE_TIME__D_GT']"
                                        format="YYYY-MM-DD"
                                    />
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('list.to','至')">
                                    <a-date-picker
                                        style="width: 100%"
                                        :placeholder="i18n('list.createTime','请输入创建时间','input')"
                                        v-model="queryParam['Q_b.CREATE_TIME__D_LT']"
                                        format="YYYY-MM-DD"
                                    />
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan" v-if="isheader">
                    <span class="table-page-search-submitButtons">
                      <a-button type="primary"  icon="search" @click="search">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                      <a-button style="margin-left: 4px"  @click="cancel">{{$ti18('rxList.resetBtn','重置')}}</a-button>
                      <a @click="toggleAdvanced" style="margin-left: 8px">
                        {{ advanced ? i18n('list.putAwayBtn','收起') : i18n('list.expansionBtn','展开') }}
                        <a-icon :type="advanced ? 'up' : 'down'" />
                      </a>
                    </span>
                            </a-col>
                            <template v-if="advanced">
                            </template>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    v-if="isShowManageTree"
                    :bordered="isBorder"
                    :allowRowSelect="false"
                    :multiSelect="false"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-bpm/bpm/core/bpmInstTracked/getMyTracked"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10', '30', '40']"
                    id-field="hisId"
                    :loadDataOnstart="true"
                    @selectChange="onSelectChange"
                    @getListData="loadDataAgen"
                >
                <span slot="curNode" slot-scope="{ text, record}">
                         {{$i18(record.curNode,"处理步骤")}}
                </span>
                <span slot="appId" slot-scope="{ text, record }">
                    {{allApps[text]?$i18(allApps[text].appName,'应用名称'):$ti18('rxList.noAppName','无')}}
                </span>
                    <span slot="billNo" slot-scope="{ text, record, index }">
                         {{record.bpmInst.billNo}}
                  </span>
                  <span slot="subject" slot-scope="{ text, record, index }">
                         <a href="javascript:;"  @click="openDetail(record.appId,record.instId)" >{{record.bpmInst.subject}}</a>
                  </span>
                  <span slot="action" slot-scope="{ text, record, index }">
                        <a href="javascript:;"  @click="removeTracked(record.instId)" :title="i18n('list.removeTracked','取消')" >{{i18n('list.removeTracked','取消')}}</a>
                  </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>


<script>
    import { BaseList, RxLayout, Util, RxFit, RxGrid } from '@lowcode/jpaas-common-lib';
    import RxCategoryTreeeditor from '@/components/redxun/rx-category-treeeditor'
    import FlowUtil from "@/views/modules/bpm/js/FlowUtil";
    import BpmInstTrackedApi from "@/api/bpm/core/bpmInstTracked";
    import { mapState} from 'vuex';
    import AppSearch from "@/views/modules/share/AppSearch";
    import RxSearchApp from "@/views/modules/share/rx-search-app";
    import instAndTaskShare from "@/views/modules/bpm/core/js/instAndTaskShare";

    export default {
        name: 'my-tracked-tasks',
        mixins: [BaseList,instAndTaskShare,FlowUtil,AppSearch],
        components: {
            RxLayout,
            RxFit,
            RxGrid,
            RxCategoryTreeeditor,
            RxSearchApp
        },
        computed: {
            ...mapState({
                // 所属应用
                allApps: state => state.appSetting ? state.appSetting.allApps : {}
            }),
        },
        data() {
            return {
                treeData: [],
                selTreeId: '',
                gridData: [],
                // 表头
                columns: [
                    {
                        title: this.$ti18('rxList.index','序号'),
                        type: 'indexColumn',
                        dataIndex: 'serial',
                        scopedSlots: { customRender: 'serial' },
                        width: 40,
                    },
                    {
                        title: this.i18n('form.itemTitle','事项标题'),
                        dataIndex: 'subject',
                        key:"subject",
                        width: 180,
                        ellipsis: false,
                        scopedSlots: { customRender: 'subject' },
                    },
                    {
                        title: this.i18n('form.bsNum','业务单号'),
                        dataIndex: 'billNo',
                        key: 'billNo',
                        width: 140,
                        scopedSlots: { customRender: 'billNo' }
                    },
                    {
                        title: this.i18n('form.processTime','处理时间'),
                        dataIndex: 'createTime',
                        width: 120,
                    },
                    {
                        title: this.i18n('form.curNode','处理步骤'),
                        dataIndex: 'curNode',
                        width: 140,
                        scopedSlots: {customRender: 'curNode'}
                    },
                    {
                        title: this.i18n('form.appId','所属应用'),
                        dataIndex: 'appId',
                        width: 120,
                        sortField: 'APP_ID_',
                        scopedSlots: {customRender: 'appId'}
                    },
                    {
                        title: this.$ti18('rxList.action','操作'),
                        dataIndex: 'action',
                        width: 50,
                        scopedSlots: { customRender: 'action' },
                    }
                ],
                statisticConfig: {
                    type:"static_bpm",
                    appIdPrefix:'t.',
                    table:"BPM_INST_TRACKED a JOIN BPM_INST t on a.INST_ID_ = t.INST_ID_",
                    field:"t.TREE_ID_",
                    whereConf:[{name:"CREATE_BY_",alias:"a.CREATE_BY_",type:"string",dateFormat:"",op:"=",value:"curUserId",valueType:"context"}]
                },
                isMyBpmClient:true,
                readKey:"task.read",
                readType:"instTracked",
                isInit:true,
                treePrefix:'b.',
            }
        },
        created(){
            this.addAppId();
        },
        methods: {
            i18n(name,text,key){
                return this.$ti18(name,text,"MyTracked",key);
            },
            addAppId(){
                let appId=this.curApp.appId;
                if(appId){
                    this.queryParam["Q_a.APP_ID__S_EQ"]=appId;
                }
            },
            selectTreeNode(curRow) {
                this.loadDataBySelectTreeNode(curRow);
            },
            instDetail(record) {
                this.openInst(record.appId,record.instId);
            },
            removeTracked(instId){
                var self_=this;
                this.$confirm({
                    title: this.$ti18('rxMsa.tipsInfo','提示信息'),
                    content: this.i18n('msa.confirmCancelTips','确认取消跟踪吗?'),
                    okText: this.$ti18('rxForm.ackBtn','确认'),
                    cancelText: this.$ti18('rxForm.cancelBtn','取消'),
                    onOk(){
                        BpmInstTrackedApi.removeTracked(instId).then(res=>{
                            self_.search();
                        })
                    }
                });
            },
            closeSearchbar(){
                //关闭过滤弹窗；（点击X触发）
                this.fitSearch = false ;
            }
        },
    }
</script>
<style scoped>

</style>

